package com.moioo.exam;

import java.util.List;

import com.moioo.util.User;

/**
 * TRole entity.
 * 
 * @author MyEclipse Persistence Tools
 */

public class TRole implements java.io.Serializable {
	private static final long serialVersionUID = 8462612314683358306L;
	private Integer id;
	private String name;
	private Integer state;
	/** default constructor */
	public TRole() {
		state = 0;
	}

	/** full constructor */
	public TRole(String name, Integer state) {
		this.name = name;
		this.state = state;
	}
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}
	public static TRoleDAO getDAO(){
		return new TRoleDAO();
	}
	public static TRole get(int id){
		return getDAO().findById(id);
	}
	public static void loadUserAuth(User user)throws Exception{
		List<TRoleUser> roles = TRoleUser.getDAO().findByUser(user.getId());
		TRoelAuthorDAO raDAO = TRoelAuthor.getDAO();
		for(TRoleUser r : roles){
			user.putAut(raDAO.findByRole(r.getId().getRoleid()));
		}
	}
}